import os
import json

def update_processed_files():
    current_dir = os.getcwd()
    xhdpi_dir = os.path.join(current_dir, 'xhdpi')
    xxhdpi_dir = os.path.join(current_dir, 'xxhdpi')
    record_file = os.path.join(current_dir, 'processed_files.json')
    
    # 初始化或读取现有的processed_files.json
    processed_files = {'xhdpi': [], 'xxhdpi': []}
    if os.path.exists(record_file):
        with open(record_file, 'r', encoding='utf-8') as f:
            processed_files = json.load(f)
    
    # 获取xhdpi目录中的所有文件名
    if os.path.exists(xhdpi_dir):
        xhdpi_files = os.listdir(xhdpi_dir)
        processed_files['xhdpi'] = [{'filename': file, 'status': 'copied'} for file in xhdpi_files]
        print(f'已更新xhdpi文件列表，共{len(xhdpi_files)}个文件')
    else:
        print('错误: xhdpi目录不存在')
        return
    
    # 获取xxhdpi目录中的所有文件名
    if os.path.exists(xxhdpi_dir):
        xxhdpi_files = os.listdir(xxhdpi_dir)
        processed_files['xxhdpi'] = [{'filename': file, 'status': 'copied'} for file in xxhdpi_files]
        print(f'已更新xxhdpi文件列表，共{len(xxhdpi_files)}个文件')
    else:
        print('警告: xxhdpi目录不存在')
    
    # 保存更新后的记录
    with open(record_file, 'w', encoding='utf-8') as f:
        json.dump(processed_files, f, indent=2, ensure_ascii=False)
    print('\nprocessed_files.json已更新完成！')

if __name__ == '__main__':
    update_processed_files()